<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Item_Base.php');
include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Enum/Enum_Item_Type.php');
include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Enum/Enum_Item_Class.php');

class Crafted_Item extends Item_Base {

    /**
     * (PHP 5)<br/>
     * Construct a Crafted_Item instance
     * @param int $guild_id
     * @param int $id
     * @param string $code
     * @param string $name
     * @param int $quality
     * @param int $quantity
     * @param int $item_class
     * @param int $skin
     * @param int $color
     * @param int $healpoint
     * @param int $durability
     * @param int $sapload
     * @param int $current_sapload
     * @param int $enchant
     * @param int $hit_rate
     * @param int $range
     * @param int $dodge_modif
     * @param int $parry_modif
     * @param int $adv_dodge_modif
     * @param int $adv_parry_modif
     * @param int $prot_factor
     * @param int $max_slash_prot
     * @param int $max_pierce_prot
     * @param int $max_blunt_prot
     * @param int $destroyed
     * @param int $healpoint_bonus
     * @param int $sap_bonus
     * @param int $stam_bonus
     * @param int $focus_bonus
     */
    public function Crafted_Item($guild_id, $id, $code, $name, $quality, $quantity,
            $item_class, $skin, $color, $healpoint, $durability,
            $sapload, $current_sapload, $enchant, $hit_rate, $range,
            $dodge_modif, $parry_modif, $adv_dodge_modif, $adv_parry_modif, $prot_factor,
            $max_slash_prot, $max_pierce_prot, $max_blunt_prot, $destroyed,
            $healpoint_bonus, $sap_bonus, $stam_bonus, $focus_bonus, $guild_name){

        $item_type_id = Enum_Item_Type::CRAFTED_ITEM_TYPE_ID;

        $this->race_id = Enum_Item_Race::convert_api_code_to_id(substr($code, 2, 1));
        $this->skin = $skin;
        $this->color = $color;
        $this->healpoint = $healpoint;
        $this->durability = $durability;
        $this->sapload = $sapload;
        $this->current_sapload = $current_sapload;
        $this->enchant = $enchant;
        $this->hit_rate = $hit_rate;
        $this->range = $range;
        $this->dodge_modif = $dodge_modif;
        $this->parry_modif = $parry_modif;
        $this->adv_dodge_modif = $adv_dodge_modif;
        $this->adv_parry_modif = $adv_parry_modif;
        $this->prot_factor = $prot_factor;
        $this->max_slash_prot = $max_slash_prot;
        $this->max_pierce_prot = $max_pierce_prot;
        $this->max_blunt_prot = $max_blunt_prot;
        $this->destroyed = $destroyed;
        $this->healpoint_bonus = $healpoint_bonus;
        $this->sap_bonus = $sap_bonus;
        $this->stam_bonus = $stam_bonus;
        $this->focus_bonus = $focus_bonus;

        parent::Item_Base($guild_id, $id, $code, $name, $quality, $quantity, $item_type_id, $item_class, $guild_name);
    }

    /**
     * (PHP 5)<br/>
     * Check if the item in parameter is the same as $this
     * @param Item_Base $item
     * @return bool
     */
    public function is_the_same_item(Item_Base $item){

        if (!parent::is_the_same_item($item)) return FALSE;

        return ($this->get_race_id() == $item->get_race_id()
                && $this->get_skin() == $item->get_skin()
                && $this->get_color() == $item->get_color()
                && $this->get_healpoint() == $item->get_healpoint()
                && $this->get_durability() == $item->get_durability()
                && $this->get_sapload() == $item->get_sapload()
                && $this->get_current_sapload() == $item->get_current_sapload()
                && $this->get_enchant() == $item->get_enchant()
                && $this->get_hit_rate() == $item->get_hit_rate()
                && $this->get_range() == $item->get_range()
                && $this->get_healpoint_bonus() == $item->get_healpoint_bonus()
                && $this->get_sap_bonus() == $item->get_sap_bonus()
                && $this->get_stam_bonus() == $item->get_stam_bonus()
                && $this->get_focus_bonus() == $item->get_focus_bonus()
                && (($this->get_dodge_modif() == $item->get_dodge_modif()) || ($this->get_dodge_modif() == 0 && $item->get_dodge_modif() == null))
                && (($this->get_parry_modif() == $item->get_parry_modif()) || ($this->get_parry_modif() == 0 && $item->get_parry_modif() == null))
                && (($this->get_adv_dodge_modif() == $item->get_adv_dodge_modif()) || ($this->get_adv_dodge_modif() == 0 && $item->get_adv_dodge_modif() == null))
                && (($this->get_adv_parry_modif() == $item->get_adv_parry_modif()) || ($this->get_adv_parry_modif() == 0 && $item->get_adv_parry_modif() == null))
                && $this->get_prot_factor() == $item->get_prot_factor()
                && $this->get_max_slash_prot() == $item->get_max_slash_prot()
                && $this->get_max_pierce_prot() == $item->get_max_pierce_prot()
                && $this->get_max_blunt_prot() == $item->get_max_blunt_prot()
                && $this->get_destroyed() == $item->get_destroyed()
                );
    }

    private $race_id;
    /**
     * (PHP 5)<br/>
     * Get item race id
     * @return int
     */
    public function get_race_id() {
        return $this->race_id;
    }
    /**
     * (PHP 5)<br/>
     * Get item race label
     * @return string
     */
    public function get_race_label(){
        return Enum_Item_Race::convert_id_to_label($this->race_id);
    }

    private $skin;
    /**
     * (PHP 5)<br/>
     * Get item skin
     * @return int
     */
    public function get_skin() {
        return $this->skin;
    }

    private $color;
    /**
     * (PHP 5)<br/>
     * Get item color
     * @return int
     */
    public function get_color() {
        return $this->color;
    }

    private $healpoint;
    /**
     * (PHP 5)<br/>
     * Get item heal points
     * @return int
     */
    public function get_healpoint() {
        return $this->healpoint;
    }

    private $durability;
    /**
     * (PHP 5)<br/>
     * Get item durability
     * @return int
     */
    public function get_durability() {
        return $this->durability;
    }

    private $sapload;
    /**
     * (PHP 5)<br/>
     * Get item max sap load
     * @return int
     */
    public function get_sapload() {
        return $this->sapload;
    }

    private $current_sapload;
    /**
     * (PHP 5)<br/>
     * Get item current sap load
     * @return int
     */
    public function get_current_sapload() {
        return $this->current_sapload;
    }

    private $enchant;
    /**
     * (PHP 5)<br/>
     * Get item enchant (-1 indicate that the weapon isn't enchanted)
     * @return int
     */
    public function get_enchant() {
        return $this->enchant;
    }

    private $hit_rate;
    /**
     * (PHP 5)<br/>
     * Get item hit rate
     * @return int
     */
    public function get_hit_rate() {
        return $this->hit_rate;
    }

    private $range;
    /**
     * (PHP 5)<br/>
     * Get item range
     * @return int
     */
    public function get_range() {
        return $this->range;
    }

    private $dodge_modif;
    /**
     * (PHP 5)<br/>
     * Get item dodge modifier
     * @return int
     */
    public function get_dodge_modif() {
        return $this->dodge_modif;
    }

    private $parry_modif;
    /**
     * (PHP 5)<br/>
     * Get item parry modifier
     * @return int
     */
    public function get_parry_modif() {
        return $this->parry_modif;
    }

    private $adv_dodge_modif;
    /**
     * (PHP 5)<br/>
     * Get item adversary dodge modifier
     * @return int
     */
    public function get_adv_dodge_modif() {
        return $this->adv_dodge_modif;
    }

    private $adv_parry_modif;
    /**
     * (PHP 5)<br/>
     * Get item adversary parry modifier
     * @return int
     */
    public function get_adv_parry_modif() {
        return $this->adv_parry_modif;
    }

    private $prot_factor;
    /**
     * (PHP 5)<br/>
     * Get item protection factor
     * @return int
     */
    public function get_prot_factor() {
        return $this->prot_factor;
    }

    private $max_slash_prot;
    /**
     * (PHP 5)<br/>
     * Get item max slash protection
     * @return int
     */
    public function get_max_slash_prot() {
        return $this->max_slash_prot;
    }

    private $max_pierce_prot;
    /**
     * (PHP 5)<br/>
     * Get item max pierce protection
     * @return int
     */
    public function get_max_pierce_prot() {
        return $this->max_pierce_prot;
    }

    private $max_blunt_prot;
    /**
     * (PHP 5)<br/>
     * Get item max blunt protection
     * @return int
     */
    public function get_max_blunt_prot() {
        return $this->max_blunt_prot;
    }

    private $destroyed;
    /**
     * (PHP 5)<br/>
     * Get item destroyed status
     * @return int
     */
    public function get_destroyed() {
        return $this->destroyed;
    }

    private $healpoint_bonus;
    /**
     * (PHP 5)<br/>
     * Get item hit points bonus
     * @return int
     */
    public function get_healpoint_bonus() {
        return $this->healpoint_bonus;
    }

    private $sap_bonus;
    /**
     * (PHP 5)<br/>
     * Get item sap bonus
     * @return int
     */
    public function get_sap_bonus() {
        return $this->sap_bonus;
    }

    private $stam_bonus;
    /**
     * (PHP 5)<br/>
     * Get item stamina bonus
     * @return int
     */
    public function get_stam_bonus() {
        return $this->stam_bonus;
    }

    private $focus_bonus;
    /**
     * (PHP 5)<br/>
     * Get item focus bonus
     * @return int
     */
    public function get_focus_bonus() {
        return $this->focus_bonus;
    }

    /**
     * (PHP 5)<br/>
     * Get item order
     * @return int
     */
    public function get_order(){
        return $this->race_id;
    }

    /**
     * (PHP 5)<br/>
     * Get item icon url
     * @return string
     */
    public function get_icon(){
        $url = parent::get_icon().'&c='.$this->color;

        if ($this->enchant != null) $url .= '&sap='.$this->enchant;
        if ($this->destroyed != null) $url .= '&destroyed='.$this->destroyed;

        return $url;
    }
}
?>
